package com.douqu.game.core.web;

import com.alibaba.fastjson.JSONObject;
import com.bean.core.util.MD5Utils;
import com.bean.core.util.TimeUtils;
import com.douqu.game.core.factory.ConstantFactory;
import com.douqu.game.core.util.LogUtils;
import com.douqu.game.core.web.request.RechargeParam;

/**
 * @author wangzhenfei
 *         2018-02-06 15:07
 */
public class RechargeCallBackParam {
    private String objectIndex;
    private String rechargeParam;
    private String password;
    private String tcd;
    private String outTradeNo;
    private int fee;
    private String channel = "";
    private String payType = "";
    private RechargeParam innerParam;
    //错误信息,目前只有苹果支付有，是从认证服务器返回的
    private String errorMsg;
    private int test;

    public JSONObject toJSONObject()
    {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("objectIndex", objectIndex);
        jsonObject.put("rechargeParam", rechargeParam);
        jsonObject.put("password", password);
        jsonObject.put("tcd", tcd);
        jsonObject.put("outTradeNo", outTradeNo);
        jsonObject.put("fee", fee);
        jsonObject.put("channel", channel);
        jsonObject.put("errorMsg", errorMsg);
        jsonObject.put("payType", payType);
        jsonObject.put("test", test);
        //不处理innerParam
        return jsonObject;
    }

    public String getRechargeParam() {
        return rechargeParam;
    }

    public void setRechargeParam(String rechargeParam) {
        this.rechargeParam = rechargeParam;
    }

    public String getTcd() {
        return tcd;
    }

    public String getObjectIndex() {
        return objectIndex;
    }


    public int getFee() {
        return fee;
    }

    public String getPassword() {
        return password;
    }

    public String getChannel() {
        return channel;
    }

    public void setChannel(String channel) {
        this.channel = channel;
    }

    public void setFee(int fee) {
        this.fee = fee;
    }

    public void setTcd(String tcd) {
        this.tcd = tcd;
    }

    public void setPassword(String password) {
        this.password = password;
    }


    public void setObjectIndex(String objectIndex) {
        this.objectIndex = objectIndex;
    }

    public String getErrorMsg() {
        return errorMsg;
    }

    public void setErrorMsg(String errorMsg) {
        this.errorMsg = errorMsg;
    }

    public String getOutTradeNo() {
        return outTradeNo;
    }

    public void setOutTradeNo(String outTradeNo) {
        this.outTradeNo = outTradeNo;
    }

    public String getPayType() {
        return payType;
    }

    public void setPayType(String payType) {
        this.payType = payType;
    }

    public int getTest() {
        return test;
    }

    public void setTest(int test) {
        this.test = test;
    }

    public boolean checkPassword(int serverId) {
        String checkString = serverId + ConstantFactory.RECHARGE_KEY + TimeUtils.getCurrentTime(TimeUtils.YYYYMMDD);
        String md5Code = MD5Utils.encodeUppercase(checkString);
        if(!md5Code.equals(password)){

            LogUtils.error("支付回调 密码错误, 待验证字符串：" + checkString);
            return false;
        }
        return true;
    }

    public RechargeParam getInnerParam() {
        if(innerParam == null){
            innerParam = new RechargeParam(rechargeParam);
        }
        return innerParam;
    }

    @Override
    public String toString() {
        return "RechargeCallBackReqDto{" +
                "objectIndex='" + objectIndex + '\'' +
                ", rechargeParam='" + rechargeParam + '\'' +
                ", password='" + password + '\'' +
                ", tcd='" + tcd + '\'' +
                ", fee=" + fee +
                ", channel='" + channel + '\'' +
                ", test='" + test + '\'' +
                ", innerParam=" + innerParam +
                '}';
    }
}
